package com.yunze.web.controller.yunze.install;

import com.alibaba.fastjson.JSON;
import com.yunze.common.utils.ServletUtils;
import com.yunze.common.utils.ip.IpUtils;
import com.yunze.common.utils.yunze.AesEncryptUtil;
import com.yunze.system.service.yunze.install.YzInstallPlacemanageService;
import com.yunze.web.core.config.MyBaseController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 按警联系人操作
 * @author liuhang
 * @date 2022-6-10
 * */

@Api("建筑物管理")
@RestController
@RequestMapping("/yunze/placemanage")
public class YzInstallPlacemanageController extends MyBaseController {

    @Autowired
    private YzInstallPlacemanageService yzInstallPlacemanageService;


    /**
     * 执行 建筑物管理 列表
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:placemanage:list')")
    @PostMapping(value = "/list", produces = {"application/json;charset=UTF-8"})
    public String SynFlow(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            return MyRetunSuccess(yzInstallPlacemanageService.PstrMap(Parammap), null);
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:placemanage:list  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("建筑物管理[列表] 操作失败！");
    }


    /**
     * 执行 建筑物管理 新增
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:placemanage:add')")
    @PostMapping(value = "/add", produces = {"application/json;charset=UTF-8"})
    public String Add(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            boolean bool = yzInstallPlacemanageService.add(Parammap);
            if(bool){
                return MyRetunSuccess("操作成功！", null);
            }else {
                return Myerr("新增 建筑物管理 操作失败！");
            }
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:placemanage:add  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("建筑物管理[新增] 操作失败！");
    }


    /**
     * 删除
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:placemanage:del')")
    @PostMapping(value = "/del", produces = {"application/json;charset=UTF-8"})
    public String deletePae(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            boolean bool = yzInstallPlacemanageService.delId(Parammap);
            if(bool){
                return MyRetunSuccess("操作成功！", null);
            }else {
                return Myerr("删除失败!");
            }
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:placemanage:del  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("删除 操作失败！");
    }


    /**
     * 修改
     * @param Pstr
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('yunze:placemanage:upd')")
    @PostMapping(value = "/upd", produces = {"application/json;charset=UTF-8"})
    public String UpdPlacemanage(@RequestBody String Pstr) {
        HashMap<String, Object> Parammap = new HashMap<String, Object>();
        if (Pstr != null) {
            Pstr = Pstr.replace("%2F", "/");//转义 /
        }
        try {
            Pstr = AesEncryptUtil.desEncrypt(Pstr);
            //  System.out.println(map);
            Parammap.putAll(JSON.parseObject(Pstr));
            boolean bool = yzInstallPlacemanageService.upd(Parammap);
            if(bool){
                return MyRetunSuccess("操作成功！", null);
            }else {
                return Myerr("修改失败!");
            }
        } catch (Exception e) {
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            logger.error("<br/> yunze:placemanage:upd  <br/> Pstr = " + Pstr + " <br/> ip =  " + ip + " <br/> ", e.getCause().toString());
        }
        return Myerr("修改 操作失败！");
    }


}
